<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>编辑用户</title>
<base href="<%=basePath%>">
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/bootstrap-3.3.6/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrapValidator.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mydialog.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css" />
<script type="text/javascript" src="<%=basePath%>js/validate/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/bootstrapValidator.js"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/zh_CN.js"></script>
<script type="text/javascript"
	src="<%=basePath%>js/common/dialog.3.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/rem.js"
	charset="utf-8"></script>
</head>
<body>
	<div id="index-hav2">
		<div class="index-hav-right" id="index-hav-right-clear">
			<div class="row">
				<div class="col-md-9">
					<span id="icon-house"> </span><span id="arrows-left">首页</span> <span
						id="arrows-left">></span><span>系统管理</span> <span id="arrows-left">></span><span>用户管理</span>
				</div>
				<div class="bank-box">
					<div class="lianlian platform">
						<div class="col-md-12" style="margin: 13px 0">
							
							<form id="defaultForm" method="post" class="form-horizontal"
								action="<%=path%>/system/admin/editUser">
								<input type="hidden" name="id" value='${admin1.id}'>
								<div class="panel panel-default">

									<div class="panel-body">
										<div class="form-group">
											<label class="col-sm-2 control-label">姓名:</label>
											<div class="col-sm-6">
												<input type="text" name="username" class="form-control"
													value="${admin1.username }">
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-2 control-label">座机:</label>
											<div class="col-sm-6">
												<input type="text" name="mobile" class="form-control"
													value="${admin1.mobile }">
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label">手机:</label>
											<div class="col-sm-6">
												<input type="text" name="phone" class="form-control"
													value="${admin1.phone }">
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label">邮箱:</label>
											<div class="col-sm-6">
												<input type="text" name="email" class="form-control"
													value="${admin1.email }">
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-2 control-label">所属组织:</label>
											<div class="col-sm-6">
												<select class=" form-control input-sm" name="orgId" id="orgId">
													<c:if test="${not empty factory}">
														<c:forEach items="${factory }" var="factory" varStatus="m">
															<option value = "${factory.orgCode }" <c:if test="${admin1.orgId == factory.orgCode}">selected</c:if>>${factory.orgName}</option>
														</c:forEach>
													</c:if>
												</select>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-2 control-label">状态:</label>
											<div class="col-sm-6">
												<select class="form-control input-sm mb15" name="isUsed">
													<option value="1"
														<c:if test="${admin1.isUsed == '1'}">selected</c:if>>启用</option>
													<option value="0"
														<c:if test="${admin1.isUsed == '0'}">selected</c:if>>禁用</option>
												</select>
											</div>
										</div>
										<div class="col-sm-8 col-btn-12">
											<button type="submit" class="btn btn-primary">保存</button>
											<!--  button type="button" class="clearForm btn btn-default">重置</button-->
											<button type="button" class="btn btn-default"
											onclick="window.location.href=
													'<%=path%>/bus/meter/returnMeterGive?url=<%=path%>/system/admin/list&flg=adminListByCondition'">返回</button>
										</div>
									</div>
									
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div id="gray-screen"></div>
</body>
<script type="text/javascript" src="<%=basePath%>js/validate/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/bootstrapValidator.js"></script>
<script type="text/javascript" src="<%=basePath%>js/common/dialog.3.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/rem.js" charset="utf-8"></script>
<script type="text/javascript">
		$(document).ready(function(){
			  $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                username: {
                    validators: {
                        notEmpty: {},
                        stringLength: {min: 3,max: 20,},
                        <%-- remote: {
                            type: 'POST',
                        	url: '<%=path%>/system/admin/getUserByName',
							message : '该用户名已存在,不可用',
							delay : 1000
						}, --%>
				regexp : {
					regexp : /^[a-zA-Z0-9_\.]+$/,
					message : '用户名只能由字母、数字、数字和下划线组成'
				}
					}
				},
				email : {
					validators : {
						notEmpty : {},
						emailAddress : {}
					}
				},
				password : {
					validators : {
						notEmpty : {}
					}
				},
				confirmPassword : {
					validators : {
						 notEmpty : {},
						 identical: {
				                        field: 'password',
				                        message: '两次密码不一致'
								}
				            /* ,  different: {
				                        field: 'username',
				                        message: '密码不能和用户名一致'
							      } */
					}
				},
				mobile: {
					validators : {
						//notEmpty : {},
						stringLength : {
							min : 7,
							max : 13,
							message : '请输入7到13位座机号码'
						},
						regexp : {
							regexp :  "([0-9]{3,4}-)?[0-9]{7,8}",
							message : '请输入正确的座机号码'
						}
					}
				},
				phone : {
					validators : {
						notEmpty : {},
						stringLength : {
							min : 11,
							max : 11,
							message : '请输入11位手机号码'
						},
					<%-- remote: {
                           	 	type: 'POST',
                        		url: '<%=path%>/system/admin/validateByPhone',
							message : '该手机号已被注册,请确认',
							delay : 1000
							}, --%>
						regexp : {
							regexp : /^1[3|5|7|8]{1}[0-9]{9}$/,
							message : '请输入正确的手机号码'
						}
					}
				},
				companyCode : {
					validators : {
						notEmpty : {}
					}
				},
				isUsed : {
					validators : {
						notEmpty : {}
					}
				},
			}
		}).on('success.form.bv', function(e) {
		            // Prevent form submission
		            e.preventDefault();

		            // Get the form instance
		            var $form = $(e.target);

		            // Get the BootstrapValidator instance
		            var bv = $form.data('bootstrapValidator');

		            // Use Ajax to submit form data


		            $.post($form.attr('action'), $form.serialize(), function(result) {

		            	if(result.message != undefined){
								var code = result.code;
				            	var grayScreen=document.getElementById("gray-screen"); 
				            	Dialog({
						                "msg": '<div class="D_alert">'+result.message+'</div>',
						                "title": "提示",
						                "showButtons": true,
						                "cancelButton": false,
						                "onComplete": function() {
						                	if(code!=1){
						                		$("body").empty();
							                 	grayScreen.style.display="none";
												window.location.href='<%=path%>/bus/meter/returnMeterGive?url=<%=path%>/system/admin/list&flg=adminListByCondition';
						                	}
						                 	
						                }
						            });
		            	}else{
		            		window.location.href='<%=path%>/bus/meter/returnMeterGive?url=<%=path%>/system/admin/list&flg=adminListByCondition';
	                	  }
		            }, 'json');
		        });
			//清空搜索条件
			$(".clearForm").click(function(){
				$("#form").find("input").val("");
			});
		});
    </script>
</html>
